//
//  JHGridTableViewCell.m
//  demo
//
//  Created by Zhen Huang on 17/10/23.
//  Copyright © 2017年 huangzhen. All rights reserved.
//

#import "JHGridTableViewCell.h"


@interface JHGridTableViewCell ()<UITextFieldDelegate>


@property (nonatomic, assign) long section;
@property (nonatomic, assign) long index;
@end



@implementation JHGridTableViewCell 


- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
        [self addSubview:self.textField];
    }
    return self;
}

- (void)layoutSubviews {
    [super layoutSubviews];
    self.textField.frame = self.textLabel.frame;
    
}

-(UITextField *)textField
{
    if (!_textField) {
        _textField = [[UITextField alloc]initWithFrame:CGRectMake(0, 0, 100, 50)];
        _textField.delegate = self;
        _textField.font = [UIFont systemFontOfSize:14];
        _textField.textAlignment = NSTextAlignmentCenter;
        _textField.keyboardType = UIKeyboardTypeNumberPad;
        [_textField addTarget:self action:@selector (textFieldChanged:) forControlEvents:UIControlEventEditingChanged];

        
    }
    return _textField;
}


- (void)arrangeCellIndex:(long)section row:(long)row {
    self.section = section;
    self.index = row;
    
}

- (void)textFieldChanged:(UITextField *)textField {
    
    if (self.jhDelegate && [self.jhDelegate respondsToSelector:@selector(workFlowsTableViewCell:textFileText:section:row:)]) {
        [self.jhDelegate workFlowsTableViewCell:self textFileText:textField.text section:self.section row:self.index];
    }

}
//- (void)textFieldDidEndEditing:(UITextField *)textField
//
//{
//    [[NSNotificationCenter defaultCenter] postNotificationName:@"changeValue" object:textField];
//    
//    
//    if (self.jhDelegate && [self.jhDelegate respondsToSelector:@selector(workFlowsTableViewCell:textFileText:section:row:)]) {
//        [self.jhDelegate workFlowsTableViewCell:self textFileText:textField.text section:self.section row:self.index];
//    }
//
//}


- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
